﻿artApp.controller('ArtController', function($scope, ArtService, $routeParams)
{
    $scope.artists = [];
    $scope.artist = {};
    $scope.artPieces = [];
    $scope.artPiece = {};
    $scope.newArtist = {};
    $scope.roles = ["Artist", "Admin"]
    $scope.loggedInUser = {};

    var id = $routeParams.id;

    $scope.showAddArtist = function()
    {
        return ArtService.isAdminLoggedIn();
    }

    $scope.showAddPiece = function()
    {
        return (ArtService.isUserLoggedIn() || ArtService.isAdminLoggedIn());
    }

    $scope.getArtists = function () {
        ArtService.getArtists().then(function (data) {
            $scope.artists = data;
            $scope.artist = ArtService.getArtist(id);
 
        }, function () {

        });
    }

    $scope.getArtists();
    

    $scope.getArtPieces = function()
    {
        ArtService.getArtPieces().then(function () {
            $scope.artPieces = ArtService.getArtPiecesForArtist(id);
        }, function () {

        });
        
    }

    $scope.getArtPieces();

    $scope.addArtPiece = function(artPiece)
    {
        artPiece.ArtistId = id;
        ArtService.addArtPiece(artPiece).then(function (){
            artPiece.Description = "";
            artPiece.ArtUrl = "";
            $scope.getArtPieces();
        }, function(){});

    }

    $scope.addArtist = function (artist) {
        ArtService.addArtist(artist).then(function () {
            artist.FirstName = "";
            artist.LastName = "";
            artist.Bio = "";
            $scope.getArtists();
        }, function () { });

    }



});